package flca.voicenav.view;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class LocationOverlay extends Overlay
{
	private Location location;
	private Paint paint1, paint2;

	public LocationOverlay(Location aLocation) {
		super();
		this.location = aLocation;

		paint1 = new Paint();
		paint1.setARGB(128, 0, 0, 255);
		paint1.setStrokeWidth(2);
		paint1.setStrokeCap(Paint.Cap.ROUND);
		paint1.setAntiAlias(true);
		paint1.setDither(false);
		paint1.setStyle(Paint.Style.STROKE);

		paint2 = new Paint();
		paint2.setARGB(64, 0, 0, 255);
	}

	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
			long when)
	{
		super.draw(canvas, mapView, shadow);

	    Point pt = mapView.getProjection().toPixels(geoPoint(location), null);

	    float radius = canvas.getHeight() / 50;
	    canvas.drawCircle(pt.x, pt.y, radius, paint2);
	    canvas.drawCircle(pt.x, pt.y, radius, paint1);

		return true;
	}

	//----------- shortcuts ------------
	private GeoPoint geoPoint(Location aLocation) {
		return geoPoint(aLocation.getLatitude(), aLocation.getLongitude());
	}
	private GeoPoint geoPoint(double lat, double lon) {
		return new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));
	}
	
}
